﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;

namespace Hockey.Shared
{
    public static class RegionNames
    {
        public static string LeftRegion = "LeftRegion";
        public static string MiddleRegion = "MiddleRegion";
        public static string CompassRegion = "CompassRegion";
        public static string MenuRegion = "MenuRegion";
        public static string ProgressRegion = "ProgressRegion";
        public static string NavigationBarRegion = "NavigationBarRegion";
        public static string TopPlayerLabel = "TopPlayerLabel";
        public static string BottomPlayerLabel = "BottomPlayerLabel";
    }

    /// <summary>
    /// Puck orientation
    /// </summary>
    public enum ePuckDir { Up, Down };

    /// <summary>
    /// Puck movement direction
    /// </summary>
    public enum eMoveDirection { North, South, West, East, NorthWest, NorthEast, SouthWest, SouthEast };

    /// <summary>
    /// Arrow button placement
    /// </summary>
    public enum eArrowPlacement { Top, Bottom, Left, Right, TopLeft, TopRight, BottomLeft, BottomRight };

    /// <summary>
    /// Type of game
    /// </summary>
    public enum eGameMode { ComputerGame, TwoPlayerGame };

    /// <summary>
    /// Engine difficulty
    /// </summary>
    public enum eEngineLevel { Novice, Advanced };
    
    /// <summary>
    /// Who is first to move
    /// </summary>
    public enum eFirstToMove { Computer, Player };

    /// <summary>
    /// Game Settings
    /// </summary>
    public struct GameSettings
    {
        public eGameMode GameMode;
        public eEngineLevel EngineLevel;
        public eFirstToMove FirstToMove;
    }


    /// <summary>
    /// Extension-method class for move direction
    /// </summary>
    public static class MoveDirectionExtension
    {
        /// <summary>
        /// Returns the opposite direction
        /// </summary>
        public static eMoveDirection Opposite(this eMoveDirection direction)
        {
            switch (direction)
            {
                case eMoveDirection.North:
                    return eMoveDirection.South;
                case eMoveDirection.South:
                    return eMoveDirection.North;
                case eMoveDirection.East:
                    return eMoveDirection.West;
                case eMoveDirection.West:
                    return eMoveDirection.East;
                case eMoveDirection.NorthEast:
                    return eMoveDirection.SouthWest;
                case eMoveDirection.NorthWest:
                    return eMoveDirection.SouthEast;
                case eMoveDirection.SouthEast:
                    return eMoveDirection.NorthWest;
                case eMoveDirection.SouthWest:
                    return eMoveDirection.NorthEast;
                default:
                    Debug.Assert(false);
                    throw new ApplicationException("Uknown Direction.");
            }
        }
    }




    /// <summary>
    /// Node coordinate structure
    /// </summary>
    public struct Coordinate
    {
        public int Row;
        public int Col;

        public Coordinate(int row, int col)
        {
            this.Row = row;
            this.Col = col;
        }

        public static bool operator ==(Coordinate c1, Coordinate c2)
        {
            return c1.Row == c2.Row && c1.Col == c2.Col;
        }

        public static bool operator !=(Coordinate c1, Coordinate c2)
        {
            return !(c1.Row == c2.Row && c1.Col == c2.Col);
        }

        public static Coordinate Empty
        {
            get
            {
                return new Coordinate(-1, -1);
            }
        }

        public override int GetHashCode()
        {
            return base.GetHashCode();
        }

        public override bool Equals(object obj)
        {
            return base.Equals(obj);
        }
    }

    // Int data type extension
    public static class IntExtension
    {
        /// <summary>
        /// Checks for odd numbers
        /// </summary>
        public static bool IsOdd(this int value)
        {
            return value % 2 != 0;
        }
    }

    /// <summary>
    /// Structure for sending messages around setting and getting player name
    /// </summary>
    public struct PlayerNameRecord
    {
        public ePuckDir PuckDirection;
        public string PlayerName;
    }
}

